
* Partidos minoritarios
* ---------------------

// SET PARAMETERS
clear all
mat votes = 12960875, 15960086, 9194637, 2294460, 3054718, 2000524, 2041608, 41556, 2494300
mat colnames votes = PAN PRI PRD PT PVEM MC NA NoReg Nulos
local ssd 52 158 56 8 19 7 0

// SIMULATE
forvalues i =  0(100000)2000000 {
	// copy
	mat foo = votes
	mat foo[1,7] = foo[1,7]-`i'
	// vote shares
	matsum foo, r(total) d
	mat foo = foo/total[1,1]
	local voteshare `=el(foo,1,1)' `=el(foo,1,2)' `=el(foo,1,3)' `=el(foo,1,4)' `=el(foo,1,5)' `=el(foo,1,6)' `=el(foo,1,7)'
	asignadipi PAN PRI PRD PT PVEM MC NA, ssd(`ssd') voteshare(`voteshare')
	// Resultados
	mat Total = nullmat(Total), r(Total)
	mat List = nullmat(List), r(List)
	mat SSD = nullmat(SSD), r(SSD)
	mat index = nullmat(index), `=el(foo,1,7)'
}

// COLLECT RESULTS
matrix rownames index = PANAL
matlist index
matlist List
mat data=(List\index)'
svmat data, names(col)

#delimit;
twoway 	(scatter PAN PANAL) 
		(scatter PRI PANAL) 
		(scatter PRD PANAL, mcolor("255 217 29")), 
		//xscale(reverse)
		ytitle(Curules de RP) 
		xtitle("% Votos de Nueva Alianza") 
		legend(rows(1)) 
		xsize(5) ysize(5)
;
#delimit cr

cd "/Users/javiermarquez/REDISTRICTING/PARTIDOS_MINORITARIOS"
graph export partidos_minoritarios.png, replace


